from qbittorrent import Client
import os
from tqdm import trange
import time

thisPath=os.environ['myCodeNexusPath'].replace('\\','/')+'/py/nhentai'

def connect_to_qbit():

    qb = Client('http://127.0.0.1:8080/', verify=False)
    qb.login()
    torrents = qb.torrents()

    return qb, torrents


qb, torrents=connect_to_qbit()

# 遍历torrent文件
result=os.walk(thisPath+"/torrent/")

for dirpath,dirnames,filenames in result:
    for i in trange(len(filenames)):
        torrent_file = open(dirpath+filenames[i], "rb")
        qb.download_from_file(torrent_file,savepath=thisPath+"/download/")
        # 添加sleep防止卡顿
        time.sleep(1)
